# -*- coding:utf-8 -*-
import collections

Card = collections.namedtuple('Card', ['rank', 'color'])


class ChinaCard(object):
    ranks = [str(n) for n in range(2, 11)] + list('JQKA')
    colors = 'black red tree clubs'.split()

    def __init__(self):
        self._cards = [Card(rank, color)
                       for rank in self.ranks for color in self.colors]
    
    def __str__(self):
        return str(self._cards)

    def __len__(self):
        return len(self._cards)

    def __getitem__(self,position):
        return self._cards[position]


if __name__ == "__main__":
    cc = ChinaCard()
    print cc

    for c in cc:
        print c

    print '-----------------------'
    from random import choice
    print choice(cc)
    print choice(cc)

    print '-----------------------'
    print cc[::3]   # x[startAt:endBefore:skip]

    print '-----------------------'
    def sort_func(c):
        suit_values = dict(black=3,red=2,tree=1,clubs=0)
        rank_value = ChinaCard.ranks.index(c.rank)
        return rank_value*len(suit_values)*suit_values[c.color]


    for c in sorted(cc,key=sort_func):
        print c